Expression | Value | Expression | Value |
---|---|---|---|
25 == 25 | true | 25 != 25 | false |
25 <= 25 | true | 25 > 25 | false |
25 >= 25 | true | 25 = 25 | illegal |
-5 < 7 | true | -305 <= 97 | true |
In an if
statement,
the true or false of a boolean expression
picks whether the true branch or the false branch
is executed.
Look at another story problem:
A clothing store wants a program that calculates the tax on an item. Clothing that costs $100 or more has a 5% tax. Clothing that costs less than $100 is tax free. Write a program that asks for the price, then calculates the tax and prints it out, and prints out the total cost of the item.
For simplicity, the price is an integer.
The print statements will be placed after the if
statement.
Here is the program, not quite finished:
Here are some program fragments to use in completing the program. Use your mouse to copy-and-paste them into the program.
tax = price * taxRate; Scanner scan = new Scanner( System.in ); price = scan.nextDouble(); final double taxRate = 0.05; price >= 100.0 import java.util.Scanner; tax = 0.0;
(Of course, it would be nice to copy the program to a file, enter your corrections and run the program.)
Complete the program by filling in the blanks.